package cn.edu.sgu.www.kafka.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author heyunlin
 * @version 1.0
 */
@Component
public class KafkaConsumer {

    @KafkaListener(topics = "hello",concurrency = "3")
    public void receiveMessage(ConsumerRecord<String, String> record) {
        extracted(record);
    }

    @KafkaListener(topics = "logs-topic",concurrency = "3")
    public void logsMessage(ConsumerRecord<String, String> record) {
        extracted(record);
    }

    private static void extracted(ConsumerRecord<String, String> record) {
        String topic = record.topic();
        long offset = record.offset();
        int partition = record.partition();
        String value = record.value();

        System.out.println("topic = " + topic);
        System.out.println("offset = " + offset);
        System.out.println("partition = " + partition);
        System.out.println("value = " + value);
    }


}